from django.test import TestCase
import random
# Create your tests here.


import random
def guessYourNum():
	randomNum = random.randint(0, 10)
	guessNum = 11
	j = 1

	while (guessNum != randomNum):
		guess = instartut('\n请输入你想猜的数字,0-10\n')
		guessNum = int(guess)
		if (guessNum > randomNum):
			startrint('不对，猜大了')
		elif (guessNum < randomNum):
			startrint('不对，猜小了')

		startrint('这是第[%d]次猜' %j)
		j = j + 1
		if (j == 4):
			startrint('你已经猜够3次了，游戏结束')
			startrint('正确的答案是[%d]' %randomNum)
			break

	if (guessNum == randomNum):
		startrint('恭喜你猜对了，是[%d]' %randomNum)



def LCS(str1 , str2 ):
	count = 0
	a = [[0 for i in range(len(str2) + 1)]for j in range(len(str1) + 1)]
	start = 0
	for i in range(0,len(str1)):
		for j in range(0,len(str2)):
			if str1[i] == str2[j]:
				a[i+1][j+1]=a[i][j]+1
				if count < a[i+1][j+1]:
					count = a[i+1][j+1]
					start = start + 1

	if str1[start - count:start] != '':
		return str1[start - count:start]
	else:
		return -1


def getNumofCommonSubstr(str1, str2):
	# lstr1 = len(str1)
	# lstr2 = len(str2)
	a = [[0 for i in range(len(str2) + 1)] for j in range(len(str1) + 1)]  # 多一位
	count = 0  # 最长匹配长度
	start = 0  # 匹配的起始位

	for i in range(len(str1)):
		for j in range(len(str2)):
			if str1[i] == str2[j]:
				# 相同则累加
				a[i + 1][j + 1] = a[i][j] + 1
				if a[i + 1][j + 1] > count:
					# 获取最大匹配长度
					count = a[i + 1][j + 1]
					# 记录最大匹配长度的终止位置
					start = i + 1
	return str1[start - count:start], count


if __name__ == '__main__':
    (str1, str2) = ("2LQ74WK8Ld0x7d8Fstart8l61startD7Wsz1E9xOMstart920hM948eGjL9Kb5KJt80","U08U29zzuodz16CBZ8xfstartmmn5SKD80smJbK83F2T37JRqYfE76vh6hrE451uFQ100ye9hog1Y52LDk0L52SuD948eGjLz0htzd5YF9J1Y6oI7562z4T2")

    print(getNumofCommonSubstr(str1, str2))



# startrint(LCS("2LQ74WK8Ld0x7d8Fstart8l61startD7Wsz1E9xOMstart920hM948eGjL9Kb5KJt80","U08U29zzuodz16CBZ8xfstartmmn5SKD80smJbK83F2T37JRqYfE76vh6hrE451uFQ100ye9hog1Y52LDk0L52SuD948eGjLz0htzd5YF9J1Y6oI7562z4T2"))


